package com.mail.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mail.dubbo.mapper.UmsMenuMapper;
import com.mail.model.db.UmsMenu;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author 吕永乐
 * @date 2022/06/21 17:17
 **/
@DubboService
public class UmsMenuApiImpl implements UmsMenuApi{

	@Autowired
	private UmsMenuMapper umsMenuMapper;

	/**
	 * 根据 menuIds 查询
	 *
	 * @param menuIds
	 * @return
	 */
	@Override
	public List<UmsMenu> getByIds(List<Long> menuIds) {
		return umsMenuMapper.selectBatchIds(menuIds);
	}

	/**
	 * 查询所有菜单列表
	 *
	 * @return
	 */
	@Override
	public List<UmsMenu> getAll() {
		return umsMenuMapper.getAll();
	}

	/**
	 * 分页查询后台菜单(分页查询)
	 *
	 * @param pageNum
	 * @param pageSize
	 * @param parentId
	 * @return
	 */
	@Override
	public Page<UmsMenu> getListByPage(Long pageNum, Long pageSize, Long parentId) {
		Page<UmsMenu> page = new Page<>(pageNum, pageSize);
		LambdaQueryWrapper<UmsMenu> wrapper = new LambdaQueryWrapper<>();
		wrapper.eq(UmsMenu::getParentId, parentId)
				.orderByAsc(UmsMenu::getSort);
		return umsMenuMapper.selectPage(page, wrapper);
	}

	/**
	 * 根据ID获取菜单详情
	 *
	 * @param id
	 * @return
	 */
	@Override
	public UmsMenu getById(Long id) {
		return umsMenuMapper.selectById(id);
	}

	/**
	 * 修改后台菜单
	 *
	 * @param umsMenu
	 * @return
	 */
	@Override
	public Integer update(UmsMenu umsMenu) {
		return umsMenuMapper.updateById(umsMenu);
	}

	/**
	 * 修改菜单显示状态
	 *
	 * @param id
	 * @param hidden
	 * @return
	 */
	@Override
	public Integer updateHiddenById(Long id, Integer hidden) {
		return umsMenuMapper.updateHiddenById(id, hidden);
	}

	/**
	 * 根据ID删除后台菜单
	 *
	 * @param id
	 * @return
	 */
	@Override
	public Integer delete(Long id) {
		return umsMenuMapper.deleteById(id);
	}

	/**
	 * 添加后台菜单
	 *
	 * @param umsMenu
	 * @return
	 */
	@Override
	public Integer create(UmsMenu umsMenu) {
		return umsMenuMapper.insert(umsMenu);
	}
}
